<template>
  <div>
    <eagle-dialog-page
      :isPage="false"
      :url="url"
      :params="params"
      :title="title"
      @initList="_initList"
      @setData="setData"
      v-bind="$attrs"
      v-on="$listeners"
      ref="eagleDialogPage"
      :option="option"
      :selectedValue="selectedValue"
      :isFuzzyQuery="true"
      fuzzyKey="OrgPostName"
    >
      <eagle-cell v-for="(item, index) in list" :key="index">
        <div class="risk_item_radio">
          <div>
            <div class="mb-5 color-gray1">{{ item.OrgPostName }}</div>
            <div class="color-gray3">
              {{ item.OrgFullName }}
            </div>
          </div>
          <eagle-radio :name="item.OrgPostCode" @click="radioClick(item)"></eagle-radio>
        </div>
      </eagle-cell>

      <template #seletedSlot>
        <van-cell name="seletedSlot" v-for="(item, index) in list" :key="index">
          <div class="risk_item_buton">
            <div class="mb-5">
              <div class="mb-5">{{ item.OrgPostName }}</div>
              <div>
                {{ item.OrgFullName }}
              </div>
            </div>
            <van-icon name="delete" @click="deleteSelect(item.OrgPostCode)" />
          </div>
        </van-cell>
      </template>
    </eagle-dialog-page>
  </div>
</template>

<script>
export default {
  props: {
    title: {
      type: String,
      default: "选择岗位",
    },
    selectedValue: {
      type: String,
      default: () => "",
    },
    url: {
      type: String,
      default: "/Public/GetChoosePostList",
    },
    orgCode: {
      type: String,
      required: false,
    },
    companyCode: {
      type: String,
      required: false,
    },
  },
  data() {
    return {
      list: [],
      option: { name: "OrgPostName", code: "OrgPostCode" },
      simSelectObject: { code: "", name: "" },
      params: [
        {
          page: 0,
          orgCode: this.$route.query.orgCode,
          companyCode: "",
        },
      ],
    };
  },
  methods: {
    _initList(list) {
      this.list = list;
      var newData = [];
      newData = [{ code: this.selectedValue, OrgPostCode: this.selectedValue }];
        this.$refs.eagleDialogPage.initSeletedData(newData);
    },
    // callbackDialog(data) {
    //   if (!data || data.length == 0) {
    //     this.$toast("您还未选择岗位");
    //     return false;
    //   }
    //   if (this.multi) {
    //   } else {
    //     this.$emit("callback", data[0]);
    //   }
    // },
    setData(data) {
      this.simSelectObject = data;
    },
    radioClick(item){
      let resultRadio = Object.assign({ code: "", name: "" }, item);
      resultRadio.code = item.OrgPostCode;
      resultRadio.name = item.OrgPostName;
      this.$emit("callback", resultRadio);
      this.$emit("update:show", false);
    }
  },
};
</script>

<style lang="less" scoped>
.risk {
  height: 100vh;
  background-color: #e8f1f8;
  .info_search {
    padding: 10px;
    border-radius: 5px !important;
    .van-field__control {
      background-color: #ffffff !important;
    }
  }
}
.risk_item_radio {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style>
